{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Finding outliers with the mean and standard deviation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from sklearn.datasets import load_breast_cancer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mean radius</th>\n",
       "      <th>mean texture</th>\n",
       "      <th>mean perimeter</th>\n",
       "      <th>mean area</th>\n",
       "      <th>mean smoothness</th>\n",
       "      <th>mean compactness</th>\n",
       "      <th>mean concavity</th>\n",
       "      <th>mean concave points</th>\n",
       "      <th>mean symmetry</th>\n",
       "      <th>mean fractal dimension</th>\n",
       "      <th>...</th>\n",
       "      <th>worst radius</th>\n",
       "      <th>worst texture</th>\n",
       "      <th>worst perimeter</th>\n",
       "      <th>worst area</th>\n",
       "      <th>worst smoothness</th>\n",
       "      <th>worst compactness</th>\n",
       "      <th>worst concavity</th>\n",
       "      <th>worst concave points</th>\n",
       "      <th>worst symmetry</th>\n",
       "      <th>worst fractal dimension</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>17.99</td>\n",
       "      <td>10.38</td>\n",
       "      <td>122.80</td>\n",
       "      <td>1001.0</td>\n",
       "      <td>0.11840</td>\n",
       "      <td>0.27760</td>\n",
       "      <td>0.3001</td>\n",
       "      <td>0.14710</td>\n",
       "      <td>0.2419</td>\n",
       "      <td>0.07871</td>\n",
       "      <td>...</td>\n",
       "      <td>25.38</td>\n",
       "      <td>17.33</td>\n",
       "      <td>184.60</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>0.1622</td>\n",
       "      <td>0.6656</td>\n",
       "      <td>0.7119</td>\n",
       "      <td>0.2654</td>\n",
       "      <td>0.4601</td>\n",
       "      <td>0.11890</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20.57</td>\n",
       "      <td>17.77</td>\n",
       "      <td>132.90</td>\n",
       "      <td>1326.0</td>\n",
       "      <td>0.08474</td>\n",
       "      <td>0.07864</td>\n",
       "      <td>0.0869</td>\n",
       "      <td>0.07017</td>\n",
       "      <td>0.1812</td>\n",
       "      <td>0.05667</td>\n",
       "      <td>...</td>\n",
       "      <td>24.99</td>\n",
       "      <td>23.41</td>\n",
       "      <td>158.80</td>\n",
       "      <td>1956.0</td>\n",
       "      <td>0.1238</td>\n",
       "      <td>0.1866</td>\n",
       "      <td>0.2416</td>\n",
       "      <td>0.1860</td>\n",
       "      <td>0.2750</td>\n",
       "      <td>0.08902</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>19.69</td>\n",
       "      <td>21.25</td>\n",
       "      <td>130.00</td>\n",
       "      <td>1203.0</td>\n",
       "      <td>0.10960</td>\n",
       "      <td>0.15990</td>\n",
       "      <td>0.1974</td>\n",
       "      <td>0.12790</td>\n",
       "      <td>0.2069</td>\n",
       "      <td>0.05999</td>\n",
       "      <td>...</td>\n",
       "      <td>23.57</td>\n",
       "      <td>25.53</td>\n",
       "      <td>152.50</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>0.1444</td>\n",
       "      <td>0.4245</td>\n",
       "      <td>0.4504</td>\n",
       "      <td>0.2430</td>\n",
       "      <td>0.3613</td>\n",
       "      <td>0.08758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>11.42</td>\n",
       "      <td>20.38</td>\n",
       "      <td>77.58</td>\n",
       "      <td>386.1</td>\n",
       "      <td>0.14250</td>\n",
       "      <td>0.28390</td>\n",
       "      <td>0.2414</td>\n",
       "      <td>0.10520</td>\n",
       "      <td>0.2597</td>\n",
       "      <td>0.09744</td>\n",
       "      <td>...</td>\n",
       "      <td>14.91</td>\n",
       "      <td>26.50</td>\n",
       "      <td>98.87</td>\n",
       "      <td>567.7</td>\n",
       "      <td>0.2098</td>\n",
       "      <td>0.8663</td>\n",
       "      <td>0.6869</td>\n",
       "      <td>0.2575</td>\n",
       "      <td>0.6638</td>\n",
       "      <td>0.17300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20.29</td>\n",
       "      <td>14.34</td>\n",
       "      <td>135.10</td>\n",
       "      <td>1297.0</td>\n",
       "      <td>0.10030</td>\n",
       "      <td>0.13280</td>\n",
       "      <td>0.1980</td>\n",
       "      <td>0.10430</td>\n",
       "      <td>0.1809</td>\n",
       "      <td>0.05883</td>\n",
       "      <td>...</td>\n",
       "      <td>22.54</td>\n",
       "      <td>16.67</td>\n",
       "      <td>152.20</td>\n",
       "      <td>1575.0</td>\n",
       "      <td>0.1374</td>\n",
       "      <td>0.2050</td>\n",
       "      <td>0.4000</td>\n",
       "      <td>0.1625</td>\n",
       "      <td>0.2364</td>\n",
       "      <td>0.07678</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   mean radius  mean texture  mean perimeter  mean area  mean smoothness  \\\n",
       "0        17.99         10.38          122.80     1001.0          0.11840   \n",
       "1        20.57         17.77          132.90     1326.0          0.08474   \n",
       "2        19.69         21.25          130.00     1203.0          0.10960   \n",
       "3        11.42         20.38           77.58      386.1          0.14250   \n",
       "4        20.29         14.34          135.10     1297.0          0.10030   \n",
       "\n",
       "   mean compactness  mean concavity  mean concave points  mean symmetry  \\\n",
       "0           0.27760          0.3001              0.14710         0.2419   \n",
       "1           0.07864          0.0869              0.07017         0.1812   \n",
       "2           0.15990          0.1974              0.12790         0.2069   \n",
       "3           0.28390          0.2414              0.10520         0.2597   \n",
       "4           0.13280          0.1980              0.10430         0.1809   \n",
       "\n",
       "   mean fractal dimension  ...  worst radius  worst texture  worst perimeter  \\\n",
       "0                 0.07871  ...         25.38          17.33           184.60   \n",
       "1                 0.05667  ...         24.99          23.41           158.80   \n",
       "2                 0.05999  ...         23.57          25.53           152.50   \n",
       "3                 0.09744  ...         14.91          26.50            98.87   \n",
       "4                 0.05883  ...         22.54          16.67           152.20   \n",
       "\n",
       "   worst area  worst smoothness  worst compactness  worst concavity  \\\n",
       "0      2019.0            0.1622             0.6656           0.7119   \n",
       "1      1956.0            0.1238             0.1866           0.2416   \n",
       "2      1709.0            0.1444             0.4245           0.4504   \n",
       "3       567.7            0.2098             0.8663           0.6869   \n",
       "4      1575.0            0.1374             0.2050           0.4000   \n",
       "\n",
       "   worst concave points  worst symmetry  worst fractal dimension  \n",
       "0                0.2654          0.4601                  0.11890  \n",
       "1                0.1860          0.2750                  0.08902  \n",
       "2                0.2430          0.3613                  0.08758  \n",
       "3                0.2575          0.6638                  0.17300  \n",
       "4                0.1625          0.2364                  0.07678  \n",
       "\n",
       "[5 rows x 30 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X, y = load_breast_cancer(return_X_y=True, as_frame=True)\n",
    "\n",
    "# display top 5 rows\n",
    "X.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_boxplot_and_hist(data, variable):\n",
    "    # creating a figure composed of two matplotlib.Axes objects (ax_box and ax_hist)\n",
    "    f, (ax_box, ax_hist) = plt.subplots(\n",
    "        2, sharex=True, gridspec_kw={\"height_ratios\": (0.50, 0.85)}\n",
    "    )\n",
    "\n",
    "    # assigning a graph to each ax\n",
    "    sns.boxplot(x=data[variable], ax=ax_box)\n",
    "    sns.histplot(data=data, x=variable, ax=ax_hist)\n",
    "\n",
    "    # Remove x axis name for the boxplot\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAV2klEQVR4nO3de5SddX3v8fc3GWLkIokkZUHIdHB5OXWRtvEMnIqXk5LqsS2KF5a61IgXTrqOS621JWA9a5XTc8NIT6XtOWoKlJByChJBqFqQpmAvCmZCkOEiSlGSISiBSlU8LYn5nj+eJ2Q7mWT2ntnP3jPze7/W2mv2fq7f38zen/3Mbz/Pb0dmIkkqx7x+FyBJ6i2DX5IKY/BLUmEMfkkqjMEvSYUZ6HcB7ViyZEkODQ31uwxJmlW2bdv2eGYuHT99VgT/0NAQIyMj/S5DkmaViHh4oul29UhSYQx+SSqMwS9JhTH4JakwBr8kFcbgl6TCzIrTOTW7vOFNZ/P9Jx7vdxlds/i4JVz/2c39LkPqGoNfXff9Jx7nh6e+p/H9HLP18p7sh62XN78PqYfs6pGkwhj8klQYg1+SCmPwS1JhDH5JKozBL0mFMfglqTAGvyQVxuCXpMIY/JJUGINfkgpj8EtSYQz+Llq1alW/S5BmBF8LM5vBL0mFMfglqTAGvyQVxuCXpMIY/JJUGINfkgpj8EtSYQx+SSqMwS9JhTH4JakwBr8kFWag3wU0ZcuWLWzatIkdO3YwODjImjVrWL16db/LksTkr8/DzT/UvLn0mm+6LXMy+Lds2cKll17KunXrWLFiBaOjo6xfvx5g1j4RpLlistfn4eYDE8675557uP322+fEa74X+TUnu3o2bdr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vBD4Jh265vAzcB7IuLouv5lEfEzEXEi8OPM/HPg48BL6mWOzcwvAr9F9caownnEr9nmvwKfAO6uA/vbwJnA/wE+GxHvpOqOeaqDbc4H/jwijqU6mv6jzHxygs+AD5KZ/xIR7waujWpI7q1U3138rxNNr1fbANwUEbsy85c7qHP/Pr8UET8HfLWu8UdUo3E+H/h4ROyjGpnzP1G9wdwQEQvrtn240/1p7nF0TkkqjF09klQYg1+SCmPwS1JhDH5JKozBL0mFMfglqTAGvyQV5v8DBerEmuyMrSAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_boxplot_and_hist(X, \"mean smoothness\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# mean plus 3 * std\n",
    "\n",
    "def find_limits(df, variable, fold):\n",
    "    var_mean = df[variable].mean()\n",
    "    var_std = df[variable].std()\n",
    "    lower_limit = var_mean - fold * var_std\n",
    "    upper_limit = var_mean + fold * var_std\n",
    "    return lower_limit, upper_limit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.05416789678205824, 0.13855266560809995)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# we find the limits\n",
    "\n",
    "lower_limit, upper_limit = find_limits(X, \"mean smoothness\", 3)\n",
    "lower_limit, upper_limit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's flag the outliers in the data set\n",
    "\n",
    "outliers = np.where(\n",
    "    (X[\"mean smoothness\"] > upper_limit) | \n",
    "    (X[\"mean smoothness\"] < lower_limit),\n",
    "    True,\n",
    "    False,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# how many outliers did we find?\n",
    "\n",
    "outliers.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_boxplot_and_hist(data, variable):\n",
    "    f, (ax_box, ax_hist) = plt.subplots(\n",
    "        2, sharex=True, gridspec_kw={\"height_ratios\": (0.50, 0.85)}\n",
    "    )\n",
    "\n",
    "    sns.boxplot(x=data[variable], ax=ax_box)\n",
    "    sns.histplot(data=data, x=variable, ax=ax_hist)\n",
    "    \n",
    "    plt.vlines(x=lower_limit, ymin=0, ymax=80, color='r')\n",
    "    plt.vlines(x=upper_limit, ymin=0, ymax=80, color='r')\n",
    "\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAWBklEQVR4nO3dfbRddX3n8feXXELkQRJJyoKQ24vLh6mLtI1zYSpaJ5Lq0CkWVEZc1YgPTLpq1VodA9auVdvpdDDSqXT6oCkwhJQpaASh6oBMBKetgrkhSHgQpQhJACVQ8QFXJSHf+WPvkOPNTe459559zj33936tddY9Zz+c/f3lnP05O7+z9+9EZiJJKsch/S5AktRbBr8kFcbgl6TCGPySVBiDX5IKM9TvAtqxcOHCHBkZ6XcZkjRQNm/e/HhmLho/fSCCf2RkhLGxsX6XIUkDJSIemmi6XT2SVBiDX5IKY/BLUmEMfkkqjMEvSYUx+CWpMANxOqcGy+vecDbfe+LxfpfRNQuOWci1n9nQ7zKkrj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vl2Zm7NahTJu4GNmZlUl66P1Mu8BrggIu6g+sGKecAwVTj/TURspQrLl7Q879cyc0f9vHe0PFerO4ErI+ItVB9Ae/2fzNxV1zAHuKGevremF9d1f7Oevo4qhA80fSJPU4U3VB94rfV9NjP3ZOY9VOPP7/03eA2wBbgd+DdUH3ZbgVdHxEcj4pcz8/tUH3r/ClwaEa+n+vBS4Yb6XYDU4ict9/e0PN7DvvdqAG/IzPtaV4yIjwDfpToyP4Qq7CZ63meY+H3/a1TB/FrgwxGxtHXdzNwTEbvqD6LxNU1X6/OOr6+19mj5+98z85PjnygiXko1TswfR8TGzPyjuptsBdXge++mHnRP5fKIX4PmRuA9e/vpI2JZPf1o4NH6qH4l1dF5W6L6YY8lmXkzcH79XEe2ufp9wEhEvKB+vBL48kGmA/wQOKrd+iZwI/COiDiyrn9xRPxMRBwP/Dgz/xb4GPDSepmjM/MLwO9SfTCqcB7xa9D8V+DjwJ11YH8bOAP4K+AzEfFWqu6Ypzp4zjnA30bE0VRH03+emU9O8B3wfjLzXyPi7cCnoxqSexPVbxf/ZKLp9WprgRsi4pHMfFUHde7d5hcj4ueAr9Y1/ohqNM4XAB+LiD1UI3P+FtUHzHURMa9u2/s73Z5mH0fnlKTC2NUjSYUx+CWpMAa/JBXG4Jekwhj8klQYg1+SCmPwS1Jh/j+aIdJRHL5KuAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_boxplot_and_hist(X, \"mean smoothness\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(7.238450329479068, 44.11599606770898)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# we find the limits in another variable\n",
    "\n",
    "lower_limit, upper_limit = find_limits(X, \"worst texture\", 3)\n",
    "lower_limit, upper_limit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's flag the outliers in the data set\n",
    "\n",
    "outliers = np.where(\n",
    "    (X[\"worst texture\"] > upper_limit) |\n",
    "    (X[\"worst texture\"] < lower_limit),\n",
    "    True,\n",
    "    False,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# how many outliers did we find?\n",
    "\n",
    "outliers.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAT5klEQVR4nO3df7DddX3n8eeLROovLD8SGQy5DS1MW9usZjdSAXGRdHeYrQPYUrXabNyFhd3VKsWaUvcPZ3ems5raKtPtFDLAks1gBVEKpR1bGsCmawdJiBoBXVmVEEQILtQfM62NvveP8w1cbm7OPffmnHvuzef5mDlzv+f7Pd/v9+0Hzyuf8znf8/mmqpAkteOocRcgSZpfBr8kNcbgl6TGGPyS1BiDX5Ias3TcBQxi2bJltWrVqnGXIUmLys6dO5+qquVT1y+K4F+1ahU7duwYdxmStKgkeWS69Q71SFJjDH5JaozBL0mNMfglqTEGvyQ1xuCXpMYsiss5deR4069cxNPffmrcZcy7405Yxq2fvGXcZUiAwa959vS3n+K7r/n3Yzn3MfddP7Zzc9/14zmvNA2HeiSpMQa/JDXG4Jekxhj8ktQYg1+SGmPwS1JjDH5JaozBL0mNMfglqTEGvyQ1xuCXpMYY/JLUGIN/np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hNPDerbQMe+/IkL557ddLcGfxqXpIlh9h0IXCocO+3bRCXA7MK/km/aJUOi8GvRSvJ+5K8u1v+SJK7uuVzk9zYLf9aN6f5l5J8aNK+30vy+0m+AJyR5IPdvQW+mOTDSc4Ezgd+r5sP/acm7XvQtu7x6W5Cre1JfibJ0iT3HZiLJsl/T/K7Xc2vAO5OcveBeiYd/6IkN3TLNyS5Osm9wKbpzjOyBtaRq6p8+FiUD3r3AfhEt7wd+By96Y8/AFxGL1z3AMvp/frxLuDC7vVF71eP0JsV8is894PGY7u/NwAXHeLcz9tGb27007rlX6A3BQHAz9GbquEX6f0S9ehu/TeAZZP2/96k5YuAGyad5w5gSb/z+PAxm4cfHbWY7QT+RZKX0bvxyf3AWuBs4N3Aa4B7qmofQPcp4PX0pt34Ib0J5gD+HvgH4LruTlB3zKaIbobSM4FPTJqd9McAquqBJFu7Y55RVT+Yw//OT1TVD/udR5oNg1+LVlX9U5KvA+8APgt8EXgDcCq9XvZpfXb/h+pNm0xV7U9yOrCOXm/7XfRmixzUUfTmkX/1IbavBp4BXt7nGJPnTnnhlG3fH/A80kAc49ditx34LeBvuuX/COyqqqI39PMvkyzrvsD9NeAzUw/Q9aR/vKr+AvhN4FXdpu8CxxzivM9uq6rvAF9P8qvd8ZLkVd3yL9ObcOz1wB8emLFzmmM/keRnkxwFvGm6E/Y7jzQbBr8Wu+3AScDfVdUT9IZstkPv9pD07kl6N/AFYGdVTTeN7THAHUm+CPwtcEW3/uPA+9K7GfhPTdln6ra3Axd3XxY/AFyQZBnwQeCSqvo/wP+gN+c8wGbg0we+3O3qvIPeJ5fHObSDztO/eaSDOTunJDXGHr8kNcbgl6TGGPyS1BiDX5IaY/BLUmMMfklqjMEvSY35/56r+vd7vvulAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_boxplot_and_hist(X, \"worst texture\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fsml",
   "language": "python",
   "name": "fsml"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
